#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
int a[N];
int n;
LL ans;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	int t = a[(1 + n) / 2];
	
	for(int i = 1; i <= n; i++) ans += abs(a[i] - t);
	cout << ans << endl;
	
	return 0;
 } 
